
public class e021 {
    public static void main(String[] args) {
        long sTime = System.currentTimeMillis();
	int sum = 0;
        for (int i = 0; i < 10000; i++) {
            if (isAmicablePair(i, amicableSum(i)) && amicableSum(i) != i) {
                sum += i;
                System.out.println(i);
            }
        }
        System.out.println(sum);
        long fTime = System.currentTimeMillis();
        System.out.println("Time: " + (fTime - sTime) + "ms");
    }

    static boolean isAmicablePair(int n, int m) {
        return (n == amicableSum(m));
    }

    static int amicableSum(int n) {
        int sum = 0;
        for (int i = 1; i <= n / 2; i++) {
            if (n % i == 0) {
                sum += i;
            }
        }
        return sum;
    }
}